Skip to main content
Version: 5.0.0

createRandom

Generate a random mnemonic (total number 12) and using TRON path "m/44'/195'" by default, return the 0th account address and private key.

Usage

TronWeb.createRandom();

Parameters

ParameterDescriptionData Type
optionsOptional parameter with three fields: { path: 'BIP44 path', extraEntropy: 'entropy', locale: 'the locale' }Object

Returns

Object - Returns randomly created account information, including mnemonic, public key, and private key. If the entered BIP44 path does not start with m/44'/195', throw an exception - Error: Invalid tron path provided.

Example

Get a mnemonic and the 0th account:

> TronWeb.createRandom();
> {
'mnemonic': {
'phrase': 'chimney **** **** **** **** **** **** **** **** **** **** stone',
'path': "m/44'/195'/0'/0/0",
'locale': 'en'
},
'privateKey': '0x7909****848c',
'publicKey':
'0x0421****ffedfc3904c9c854854a5019b8373d2aed0c6b96ff5f3be07722403088742b0949a6c9',
'address': 'TEFAyPnainfiAJBuhExfMLJeHHxD2DZJmF'
};

If you want to get an account with the custom path index, you can provide the path.

> TronWeb.createRandom({path: "m/44'/195'/1'/0/0"});
> {
"mnemonic": {
"phrase": "mixture **** **** **** **** **** **** **** **** **** **** question",
"path": "m/44'/195'/1'/0/0",
"locale": "en"
},
"privateKey": "0xd53b****8bbd",
"publicKey": "0x046e****0c9370b449e88966acb28bde3ab751afa119c91186d5bd9a250f9b43e32486108b72a7",
"address": "THwRMnsVjeXfC4sbvLpFknTEjaNisvYnQy"
}